package Client.GUI;

import java.util.ArrayList;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import Server.DataBase.Request;

public class RequestTableModel extends AbstractTableModel {

          /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

                Vector<String[]> cache; // will hold String[] objects . . .

                int colCount=7;

                String[] headers = {" Id Request", "Id Lesson ", "Coures Name", "Id User ", "Last Name", "First Name", "Mode"};

                public RequestTableModel() {
                        cache = new Vector<String[]>();
                }

                public String getColumnName(int i) {
                        return headers[i];
                }

                public int getColumnCount() {
                        return colCount;
                }

                public int getRowCount() {
                        return cache.size();
                }

                public Object getValueAt(int row, int col) {
                        return ((String[]) cache.elementAt(row))[col];
                }
          
                public void setValueAt(int row, int col, String msg){
                  ((String[]) cache.elementAt(row))[col] = msg;
                  fireTableChanged(null);
          }
          
          public void setArray(ArrayList<Request> array){
                  cache.removeAllElements();
                  for (int i=0; i<array.size(); i++) addToArray(array.get(i));
                  fireTableChanged(null);
          }
          
          public void addToArray(Request request){
                  String[] record = new String[colCount];
                  record[0] = Integer.toString(request.getIdRequest());
                  record[1] = Integer.toString(request.getLesson().getIdLesson());
                  record[2] = request.getLesson().getCourse().getCourseName();
                  record[3] = Integer.toString(request.getUser().getIdUser());
                  record[4] = request.getUser().getLastName();
                  record[5] = request.getUser().getFirstName();
                  if (request.getMode()==1)
                          record[6] = "Assign To Course";
                  if (request.getMode()==2)
                          record[6] = "Remove From Course";
                  if (request.getMode()==3)
                          record[6] = "Change Teacher";
                  cache.addElement(record);
          }
        }

